package com.ruoyi.web.controller.wnjk.app.shop;

import java.util.List;

import com.ruoyi.system.wnjk.domain.po.ShopCart;
import com.ruoyi.system.wnjk.service.IShopCartService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 订单详情Controller
 *
 * @author ruoyi
 * @date 2025-03-11
 */
@RestController
@RequestMapping("/app/shop/cart")
public class AppShopCartController extends BaseController
{
    @Autowired
    private IShopCartService shopCartService;

    /**
     * 查询订单详情列表
     */
//    @PreAuthorize("@ss.hasPermi('system:cart:list')")
    @GetMapping("/list/{userId}")
    public TableDataInfo list(@PathVariable Long userId)
    {
        startPage();
        List<ShopCart> list = shopCartService.selectShopCartList(userId);
        return getDataTable(list);
    }

    /**
     * 获取订单详情详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:cart:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(shopCartService.selectShopCartById(id));
    }

    /**
     * 新增订单详情
     */
    @PreAuthorize("@ss.hasPermi('system:cart:add')")
    @Log(title = "订单详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopCart shopCart)
    {
        return toAjax(shopCartService.insertShopCart(shopCart));
    }

    /**
     * 修改订单详情
     */
    @PreAuthorize("@ss.hasPermi('system:cart:edit')")
    @Log(title = "订单详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopCart shopCart)
    {
        return toAjax(shopCartService.updateShopCart(shopCart));
    }

    /**
     * 删除订单详情
     */
    @PreAuthorize("@ss.hasPermi('system:cart:remove')")
    @Log(title = "订单详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shopCartService.deleteShopCartByIds(ids));
    }
}
